package com.enqualcomm.kids.mvp.reai;

import com.enqualcomm.kids.mvp.location.LocationCallBack;
import com.enqualcomm.kids.mvp.location.MyLocationClient;
import com.enqualcomm.kids.network.socket.response.LocationResult;

import rx.Single;
import rx.SingleSubscriber;

/**
 * Created by yinzhiqun on 2016/3/29.
 * 如果手表已关机，返回“手表已关机”，否则返回null
 */
public class SyncTimeObservable implements Single.OnSubscribe<String> {
    private String terminalid;
    private String userkey;
    private String userid;

    public SyncTimeObservable(String terminalid, String userkey, String userid) {
        this.terminalid = terminalid;
        this.userkey = userkey;
        this.userid = userid;
    }

    @Override
    public void call(final SingleSubscriber<? super String> singleSubscriber) {
        MyLocationClient.syncTime(new LocationCallBack() {
            @Override
            public void onReceiveLocation(int state, LocationResult.Data content) {
                if (state == 102) {
                    singleSubscriber.onSuccess("已关机");
                }else{
                    singleSubscriber.onError(null);
                }
                singleSubscriber.unsubscribe();
            }
        }, userkey, userid, terminalid);
    }
}
